﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace jephyr
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            switch (this.WindowState)
            {
                case WindowState.Normal:
                    this.WindowState = WindowState.Maximized;
                    break;

                case WindowState.Maximized:
                    this.WindowState = WindowState.Normal;
                    break;
            }
        }

        private void window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
                this.Left = e.GetPosition(null).X - (this.Width / 2);
                this.Top = e.GetPosition(null).Y - 20;
            }

            // Allow the window to be draggable without the title bar.
            DragMove();
        }

        private void window_StateChanged(object sender, EventArgs e)
        {
            switch (this.WindowState)
            {
                case WindowState.Maximized:
                    appWindow.Margin = new Thickness
                    {
                        Top = 8,
                        Left = 8,
                        Right = 8,
                        Bottom = 8
                    };
                    this.WindowState = WindowState.Maximized;
                    btnRestore.Visibility = Visibility.Visible;
                    btnMaximize.Visibility = Visibility.Collapsed;
                    break;

                case WindowState.Normal:
                    this.WindowState = WindowState.Normal;
                    appWindow.Margin = new Thickness
                    {
                        Top = 0,
                        Left = 0,
                        Right = 0,
                        Bottom = 0
                    };
                    btnRestore.Visibility = Visibility.Collapsed;
                    btnMaximize.Visibility = Visibility.Visible;
                    break;
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void btnRestore_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Normal;
        }

        private void btnMaximize_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Maximized;
        }

        private void btnMinimize_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }
    }
}
